/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.model.command;

import static com.cea.papyrus.diagram.sequence.sedi.model.util.ModelUtil.getFragments;

import java.util.List;

import org.eclipse.gef.commands.Command;
import org.eclipse.uml2.uml.Interaction;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.InteractionOperand;

/**
 * Superclass for many commands that deal with elements in a specific 
 * namespace.
 * 
 * @author frankd@ifi.uio.no
 */
public abstract class AbstractNamespaceCommand extends Command {
	
	protected InteractionFragment namespace;
	
	public void setNamespace(final InteractionFragment namespace) {
		if (!(namespace instanceof Interaction || namespace instanceof InteractionOperand))
			throw new IllegalArgumentException(String.valueOf(namespace));
		this.namespace = namespace;
	}

	protected List<InteractionFragment> getNamespaceFragments() {
		List<InteractionFragment> fragments;
		if (namespace instanceof Interaction)
			fragments = getFragments((Interaction)namespace);
		else
			fragments = getFragments((InteractionOperand)namespace);
		return fragments;
	}
	
	@Override
	public void dispose() {
		namespace = null;
	}	
}
